<%--
  Created by IntelliJ IDEA.
  User: zuxia
  Date: 2018/7/19
  Time: 13:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" href="css/amazeui.min.css">
    <link rel="stylesheet" href="css/admin.css">
    <style>
        .admin-main{
            padding-top: 0px;
        }
        .onError{ color: red; }
        .onSuccess{ color: green; }
    </style>
</head>

<body>

<div class="am-cf admin-main">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-g">
                <form class="am-form am-form-horizontal" action="/isFull-admin/addType.action" method="post" target="_parent">
                    <div class="am-form-group" style="margin-top: 50px">
                        <label  class="am-u-sm-3 am-form-label">
                            菜品类型名称
                        </label>
                        <div class="am-u-sm-9">
                            <input id="roleName"  placeholder="请输入菜品类型名称" class="required" name="foodType.tName" type="text">
                        </div>
                        <div>
                            <div class="am-u-sm-9 am-u-sm-push-3" style="margin: 50px 0 0 80px">
                                <input id="addRole" class="am-btn am-btn-success" value="添加" type="submit">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>

<script src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">

    $("form :input").blur(function() {
        $(".msg").empty();
        var $parent = $(this).parent();
        //验证姓名
        if ($(this).is("#roleName")) {
            var nameVal = $.trim(this.value); //原生js去空格方式：this.replace(/(^\s*)|(\s*$)/g, "")
            var regName = /[~#^$@%&!*()<>:;'"{}【】  ]/;
            if (nameVal == "" || regName.test(nameVal)) {
                var errorMsg = " 姓名非空，不包含特殊字符！";
                $parent.append("<span class='msg onError'>" + errorMsg + "</span>");
                $(".msg").attr("color","red");
            }
        }
    })
    //点击确定按钮时，通过trigger()来触发文本框的失去焦点事件
    $("#addRole").click(function(){
        //trigger 事件执行完后，浏览器会为submit按钮获得焦点
        $("form .required:input").trigger("blur");
        var numError  = $("form .onError").text();
        if(numError != ""){
            return false;
        }else{
            return true;
        }
    });
</script>
</html>

